//:C07:VectorCoreDump.cpp
// Invalidating an iterator.
#include <iterator>
#include <iostream>
#include <ostream>
#include <vector>
using namespace std;

int main(void)
{
    vector<int> vi(10, 0);
    ostream_iterator<int> out(cout, " ");
    vector<int>::iterator i = vi.begin();
    *i = 47;
    copy(vi.begin(), vi.end(), out);
    cout << endl;

    // Force it to move memory (could also just add
    // enough objects)
    vi.resize(vi.capacity() + 1);
    // Now i points to wrong memory:
    *i = 48;    // Access violation
    // No change to vi[0]
    copy(vi.begin(), vi.end(), out);    
}